package com.yzc.android.network.request;

import java.util.HashMap;
import java.util.Map;

import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.yzc.android.network.base.KDRequestQueue;
import com.yzc.android.network.base.KDJsonObjectRequest;
import com.yzc.android.network.base.VolleyManager;
import org.json.JSONObject;

/**
 * Created by yzc on 16/1/28.
 */
public class AccountRequestFactory {

    public static KDJsonObjectRequest getUserInfo(final boolean notify, final Response.Listener<JSONObject> successListener,
                                                   final Response.ErrorListener errorListener) {
        //String token = UserStatusManager.getToken();
        //if (TextUtils.isEmpty(token)) return null;
        KDRequestQueue queue = VolleyManager.getRequestQueue();
        Map<String, String> params = new HashMap<>();
        params.put("method", "c.my.infoview");
        //params.put("token", token);

        KDJsonObjectRequest request = new KDJsonObjectRequest(Request.Method.POST, params, new Response.Listener<JSONObject>() {
            @Override
            public void onResponse(JSONObject response) {
                //UserStatusManager.parserAndSaveUserInfo(response);
                if (successListener != null)
                {
                    successListener.onResponse(response);
                }
                //if (notify) {
                //    UserStatusManager.notifyUserInfoUpdateSuccess();
                //}
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                if (errorListener != null)
                {
                    errorListener.onErrorResponse(error);
                }
                //if (notify) {
                //    UserStatusManager.notifyUserInfoUpdateFailed();
                //}
            }
        });
        queue.add(request, errorListener);
        return request;
    }


    //public static KDGsonRequest<cn.edaijia.android.client.network.EDJBaseResponse> saveUserInfo(final UserInfo userInfo,
    //                                                           final Response.Listener<cn.edaijia.android.client.network.EDJBaseResponse> successListener,
    //                                                           final Response.ErrorListener errorListener) {
    //    String token = UserStatusManager.getToken();
    //    if (TextUtils.isEmpty(token) || userInfo == null) return null;
    //    cn.edaijia.android.client.network.EDJRequestQueue queue = VolleyManager.getRequestQueue();
    //    Map<String, String> params = new HashMap<>();
    //    params.put("method", "c.my.infosave");
    //    params.put("token", token);
    //    params.put("name", userInfo.name);
    //    params.put("gender", String.valueOf(userInfo.gender));
    //    params.put("backup_phone", userInfo.backup_phone);
    //    params.put("address", userInfo.address);
    //    KDGsonRequest<cn.edaijia.android.client.network.EDJBaseResponse> myReq = new KDGsonRequest<>(Request.Method.POST, cn.edaijia.android.client.network.EDJBaseResponse.class, params, new Response.Listener<cn.edaijia.android.client.network.EDJBaseResponse>() {
    //        @Override
    //        public void onResponse(cn.edaijia.android.client.network.EDJBaseResponse response) {
    //            UserStatusManager.saveUserInfo(userInfo);
    //            if (successListener != null) {
    //                successListener.onResponse(response);
    //            }
    //            UserStatusManager.notifyUserInfoUpdateSuccess();
    //        }
    //    }, new Response.ErrorListener() {
    //        @Override
    //        public void onErrorResponse(VolleyError error) {
    //            if (errorListener != null)
    //            {
    //                errorListener.onErrorResponse(error);
    //            }
    //            UserStatusManager.notifyUserInfoUpdateFailed();
    //        }
    //    });
    //    queue.add(myReq, errorListener);
    //    return myReq;
    //}
    //
    //public static cn.edaijia.android.client.network.EDJJsonObjectRequest login(String phone, String verifycode, int verifyType,
    //                                         Response.Listener<JSONObject> successListener,
    //                                         Response.ErrorListener errorListener) {
    //    if (TextUtils.isEmpty(phone) || TextUtils.isEmpty(verifycode)) return null;
    //    cn.edaijia.android.client.network.EDJRequestQueue queue = VolleyManager.getRequestQueue();
    //    Map<String, String> params = new HashMap<>();
    //    params.put("method", "c.login");
    //    params.put("phone", phone);
    //    params.put("passwd", verifycode);
    //    params.put("os", "android");
    //    params.put("macaddress", PhoneFunc.getMacAddress());
    //    params.put("verify_type", verifyType + "");
    //    cn.edaijia.android.client.network.EDJJsonObjectRequest request = new cn.edaijia.android.client.network.EDJJsonObjectRequest(Request.Method.POST, params, successListener, errorListener);
    //    queue.add(request, errorListener);
    //    return request;
    //}
    //
    //public static cn.edaijia.android.client.network.EDJJsonObjectRequest logout(Response.Listener<JSONObject> successListener, Response.ErrorListener errorListener)
    //{
    //    String token = UserStatusManager.getToken();
    //    if (TextUtils.isEmpty(token) || UserStatusManager.getUserInfo() == null) return null;
    //    cn.edaijia.android.client.network.EDJRequestQueue queue = VolleyManager.getRequestQueue();
    //    Map<String, String> params = new HashMap<>();
    //    params.put("method", "c.logout");
    //    params.put("phone", UserStatusManager.getUserInfo().phone);
    //    params.put("token", token);
    //    cn.edaijia.android.client.network.EDJJsonObjectRequest request = new cn.edaijia.android.client.network.EDJJsonObjectRequest(Request.Method.POST, params, successListener, errorListener);
    //    queue.add(request, errorListener);
    //    return request;
    //}
    //
    //public static cn.edaijia.android.client.network.EDJJsonObjectRequest getVerifyCode(String phone, Response.Listener<JSONObject> successListener, Response.ErrorListener errorListener)
    //{
    //    if (TextUtils.isEmpty(phone) || !Utils.checkIsPhone(phone)) return null;
    //    cn.edaijia.android.client.network.EDJRequestQueue queue = VolleyManager.getRequestQueue();
    //    Map<String, String> params = new HashMap<>();
    //    params.put("method", "c.prelogin");
    //    params.put("phone", phone);
    //    cn.edaijia.android.client.network.EDJJsonObjectRequest request = new cn.edaijia.android.client.network.EDJJsonObjectRequest(Request.Method.POST, params, successListener, errorListener);
    //    queue.add(request, errorListener);
    //    return request;
    //}
    //
    //public static cn.edaijia.android.client.network.EDJJsonObjectRequest getVoiceVerifyCode(String phone, Response.Listener<JSONObject> successListener, Response.ErrorListener errorListener)
    //{
    //    if (TextUtils.isEmpty(phone) || !Utils.checkIsPhone(phone)) return null;
    //    cn.edaijia.android.client.network.EDJRequestQueue queue = VolleyManager.getRequestQueue();
    //    Map<String, String> params = new HashMap<>();
    //    params.put(Constants.KEY_METHOD, Constants.METHOD_VERIFY_VOICE);
    //    params.put(Constants.KEY_PHONE, phone);
    //    cn.edaijia.android.client.network.EDJJsonObjectRequest request = new cn.edaijia.android.client.network.EDJJsonObjectRequest(Request.Method.POST, params, successListener, errorListener);
    //    queue.add(request, errorListener);
    //    return request;
    //}
    //
    //public static cn.edaijia.android.client.network.EDJJsonObjectRequest sendLoginSMS(String phone, Response.Listener<JSONObject> successListener, Response.ErrorListener errorListener)
    //{
    //    if (TextUtils.isEmpty(phone) || !Utils.checkIsPhone(phone)) return null;
    //    cn.edaijia.android.client.network.EDJRequestQueue queue = VolleyManager.getRequestQueue();
    //    Map<String, String> params = new HashMap<>();
    //    params.put("method", "c.sendlogin");
    //    params.put(Constants.KEY_PHONE, phone);
    //    cn.edaijia.android.client.network.EDJJsonObjectRequest request = new cn.edaijia.android.client.network.EDJJsonObjectRequest(Request.Method.POST, params, successListener, errorListener);
    //    queue.add(request, errorListener);
    //    return request;
    //}
    //
    //public static cn.edaijia.android.client.network.EDJJsonObjectRequest bindPhone(String phone, Response.Listener<JSONObject> successListener, Response.ErrorListener errorListener)
    //{
    //    if (TextUtils.isEmpty(phone) || !Utils.checkIsPhone(phone)) return null;
    //    cn.edaijia.android.client.network.EDJRequestQueue queue = VolleyManager.getRequestQueue();
    //    Map<String, String> params = new HashMap<>();
    //    params.put("method", "c.loginstatus");
    //    params.put(Constants.KEY_PHONE, phone);
    //    cn.edaijia.android.client.network.EDJJsonObjectRequest request = new cn.edaijia.android.client.network.EDJJsonObjectRequest(Request.Method.POST, params, successListener, errorListener);
    //    queue.add(request, errorListener);
    //    return request;
    //}
    //
    //public static cn.edaijia.android.client.network.EDJJsonObjectRequest getOrderCommentState(final Response.Listener<JSONObject> successListener, final Response.ErrorListener errorListener)
    //{
    //    if (TextUtils.isEmpty(UserStatusManager.getToken())) return null;
    //    cn.edaijia.android.client.network.EDJRequestQueue queue = VolleyManager.getRequestQueue();
    //    Map<String, String> params = new HashMap<>();
    //    params.put("method", "c.order.history.commentstate");
    //    cn.edaijia.android.client.network.EDJJsonObjectRequest request = new cn.edaijia.android.client.network.EDJJsonObjectRequest(Request.Method.POST, params, successListener, errorListener);
    //    queue.add(request, errorListener);
    //    return request;
    //}
    //
    //public static cn.edaijia.android.client.network.EDJJsonObjectRequest updateOrdersReadTime(final Response.Listener<JSONObject> successListener, final Response.ErrorListener errorListener)
    //{
    //    if (TextUtils.isEmpty(UserStatusManager.getToken())) return null;
    //    cn.edaijia.android.client.network.EDJRequestQueue queue = VolleyManager.getRequestQueue();
    //    Map<String, String> params = new HashMap<>();
    //    params.put("method", "c.order.history.markread");
    //    cn.edaijia.android.client.network.EDJJsonObjectRequest request = new cn.edaijia.android.client.network.EDJJsonObjectRequest(Request.Method.POST, params, new Response.Listener<JSONObject>() {
    //        @Override
    //        public void onResponse(JSONObject response) {
    //            Const.EVENT_BUS.post(new OrderCommentEvent(""));
    //        }
    //    }, errorListener);
    //    queue.add(request, errorListener);
    //    return request;
    //}
    //
    //public static cn.edaijia.android.client.network.EDJJsonObjectRequest getInvoiceInfo(final Response.Listener<JSONObject> successListener, final Response.ErrorListener errorListener)
    //{
    //    if (TextUtils.isEmpty(UserStatusManager.getToken())) return null;
    //    cn.edaijia.android.client.network.EDJRequestQueue queue = VolleyManager.getRequestQueue();
    //    Map<String, String> params = new HashMap<>();
    //    params.put("method", "c.my.invoice");
    //    cn.edaijia.android.client.network.EDJJsonObjectRequest request = new cn.edaijia.android.client.network.EDJJsonObjectRequest(Request.Method.POST, params, new Response.Listener<JSONObject>() {
    //        @Override
    //        public void onResponse(JSONObject response) {
    //            JSONObject voiceInfo = response.optJSONObject("data");
    //            if (voiceInfo != null)
    //            {
    //                InvoiceInfo invoiceInfo = new InvoiceInfo();
    //                invoiceInfo.setPhone(voiceInfo.optString("telephone"));
    //                invoiceInfo.setAddress(voiceInfo.optString("address"));
    //                invoiceInfo.setTitle(voiceInfo.optString("title"));
    //                invoiceInfo.setName(voiceInfo.optString("contact"));
    //                invoiceInfo.setClientAmount(voiceInfo.optInt("amount"));
    //                invoiceInfo.setMinamount(voiceInfo.optInt("minamount"));
    //                UserStatusManager.setInvoiceInfo(invoiceInfo);
    //                if (successListener != null)
    //                {
    //                    successListener.onResponse(response);
    //                }
    //            }
    //        }
    //    }, errorListener);
    //    queue.add(request, errorListener);
    //    return request;
    //}
    //
    //public static cn.edaijia.android.client.network.EDJJsonObjectRequest saveInvoiceInfo(int amount, String clientRemark, final InvoiceInfo invoice, String
    //        type, String payType, String wealth, final Response.Listener<JSONObject> successListener, final Response.ErrorListener errorListener)
    //{
    //    if (TextUtils.isEmpty(UserStatusManager.getToken())) return null;
    //    cn.edaijia.android.client.network.EDJRequestQueue queue = VolleyManager.getRequestQueue();
    //    Map<String, String> params = new HashMap<>();
    //    params.put("method", "c.my.invoicesave");
    //    params.put("invoice_title", invoice.getTitle());
    //    params.put("invoice_telephone", invoice.getPhone());
    //    params.put("invoice_contact", invoice.getName());
    //    params.put("invoice_address", invoice.getAddress());
    //    params.put("client_amount", String.valueOf(amount));
    //    params.put("client_remark", clientRemark);
    //    params.put("type", type);
    //    params.put("pay_type", payType);
    //    params.put("wealth", wealth);
    //
    //    cn.edaijia.android.client.network.EDJJsonObjectRequest request = new cn.edaijia.android.client.network.EDJJsonObjectRequest(Request.Method.POST, params, new Response.Listener<JSONObject>() {
    //        @Override
    //        public void onResponse(JSONObject response) {
    //            UserStatusManager.setInvoiceInfo(invoice);
    //            if (successListener != null)
    //            {
    //                successListener.onResponse(response);
    //            }
    //        }
    //    }, errorListener);
    //    queue.add(request, errorListener);
    //    return request;
    //}
    //
    //public static cn.edaijia.android.client.network.EDJJsonObjectRequest getTransactionList(String type, String minId, int pageSize, final Response.Listener<JSONObject> successListener, final Response.ErrorListener errorListener)
    //{
    //    if (TextUtils.isEmpty(type) || TextUtils.isEmpty(minId) || pageSize <= 0) return null;
    //    cn.edaijia.android.client.network.EDJRequestQueue queue = VolleyManager.getRequestQueue();
    //    Map<String, String> params = new HashMap<>();
    //    params.put("method", "c.my.feelist");
    //    params.put("type", type);
    //    params.put("min_id", minId);
    //    params.put("count", String.valueOf(pageSize));
    //    cn.edaijia.android.client.network.EDJJsonObjectRequest request = new cn.edaijia.android.client.network.EDJJsonObjectRequest(Request.Method.POST, params, successListener, errorListener);
    //    queue.add(request, errorListener);
    //    return request;
    //}
    //
    //public static cn.edaijia.android.client.network.EDJJsonObjectRequest getECoinList(int pageNo, int pageSize, final Response.Listener<JSONObject> successListener, final Response.ErrorListener errorListener)
    //{
    //    if (TextUtils.isEmpty(UserStatusManager.getToken()) || pageNo < 0 || pageSize <= 0) return null;
    //    cn.edaijia.android.client.network.EDJRequestQueue queue = VolleyManager.getRequestQueue();
    //    Map<String, String> params = new HashMap<>();
    //    params.put("method", Constants.METHOD_EMONEY_LIST);
    //    params.put("page_size", String.valueOf(pageSize));
    //    params.put("page_num", String.valueOf(pageNo));
    //    cn.edaijia.android.client.network.EDJJsonObjectRequest request = new cn.edaijia.android.client.network.EDJJsonObjectRequest(Request.Method.POST, params, successListener, errorListener);
    //    queue.add(request, errorListener);
    //    return request;
    //}
    //
    //public static cn.edaijia.android.client.network.EDJJsonObjectRequest getInvoiceList(int pageNo, int pageSize, final Response.Listener<JSONObject> successListener, final Response.ErrorListener errorListener)
    //{
    //    if (TextUtils.isEmpty(UserStatusManager.getToken()) || pageNo < 0 || pageSize <= 0) return null;
    //    cn.edaijia.android.client.network.EDJRequestQueue queue = VolleyManager.getRequestQueue();
    //    Map<String, String> params = new HashMap<>();
    //    params.put("method", Constants.METHOD_MY_INVOICE_LIST);
    //    params.put("pageSize", String.valueOf(pageSize));
    //    params.put("pageNumber", String.valueOf(pageNo));
    //    cn.edaijia.android.client.network.EDJJsonObjectRequest request = new cn.edaijia.android.client.network.EDJJsonObjectRequest(Request.Method.POST, params, successListener, errorListener);
    //    queue.add(request, errorListener);
    //    return request;
    //}
    //
    //public static cn.edaijia.android.client.network.EDJJsonObjectRequest saveBookingAddress(Address address, String type, final Response.Listener<JSONObject> successListener, final Response.ErrorListener errorListener)
    //{
    //    if (TextUtils.isEmpty(UserStatusManager.getToken()) || address == null || TextUtils.isEmpty(type)) return null;
    //    cn.edaijia.android.client.network.EDJRequestQueue queue = VolleyManager.getRequestQueue();
    //    Map<String, String> params = new HashMap<>();
    //    params.put("method", "c.my.address_save");
    //    params.put("address", address.getName());
    //    params.put("lng", address.lng+"");
    //    params.put("lat", address.lat+"");
    //    params.put("type", type);
    //    cn.edaijia.android.client.network.EDJJsonObjectRequest request = new cn.edaijia.android.client.network.EDJJsonObjectRequest(Request.Method.POST, params, successListener, errorListener);
    //    queue.add(request, errorListener);
    //    return request;
    //}

}
